﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using com.tiyma.httpmoudle;

namespace com.tiyma.web
{
    public partial class Common : System.Web.UI.MasterPage
    {

        private string m_nav = "<a  href=\"/user/Reg.aspx\">注册</a>|<a  href=\"/user/Login.aspx\">登录</a>";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["k"]))
            {
                lblKey.Text = string.Format("<script>SetKey('{0}');</script>", Request["k"]);
            }

            if (Token != null)
            {
                lblNav.Text = string.Format("{0}|<a href=\"/user/index.aspx\" target=\"_blank\">我的信息</a>|<a href=\"/user/bookcase.aspx\" target=\"_blank\">我的书架</a>|<a href=\"/Out.aspx?retUrl={1}\">退出</a>", !string.IsNullOrEmpty(Token.NickName) ? Token.NickName : Token.UserName,Request.Url.ToString());
            }
            else
            {
                lblNav.Text=m_nav;
            }
        }


        /// <summary>
        /// 用户登录Token
        /// </summary>
        protected UserToken Token
        {
            get
            {
                UserToken token = HttpContext.Current.Items[AuthenticateModule.CONTEXT_ROLE_KEY] as UserToken;
                return token;
            }

        }

        /// <summary>
        /// 设置关键字
        /// </summary>
        /// <param name="keyword"></param>
        public void SetPageMetaKeyword(string keyword)
        {
            if (!string.IsNullOrEmpty(keyword))
            {
                metaKeywords.Content = keyword;
            }
        }

        /// <summary>
        /// 设置描述关键字
        /// </summary>
        /// <param name="description"></param>
        public void SetPageMetaDescription(string description)
        {
            if (!string.IsNullOrEmpty(description))
            {
                metaDescription.Content = description;
            }
        }

        /// <summary>
        /// 外部调用定位CSS
        /// </summary>
        /// <param name="cssFile"></param>
        public void SetCssFile(string cssFile)
        {
            MainStyle.Href = cssFile;
        }
    }
}
